/* 

Replication syntax BJPolS article
"Intergenerational social mobility, political socialization, and support for the left under post-industrial realignment"
Dr. Macarena Ares, University of Barcelona
Dr. Mathilde M. van Ditmars, University of Lucerne
March 2022 (Stata version 16)

File 1/4. BHPS-UKHLS Data preparation 
*/

*British Household Panel Study (BHPS), years 1999-2009
*UK Household Longitudinal Study (UKHLS), years 2009-2019
*Data version used: Understanding Society Waves 1-10 and Harmonised BHPS: Waves 1-18, 13th Edition.
*see https://beta.ukdataservice.ac.uk/datacatalogue/doi/?id=6614#!#14


*DATASET WORKING FILE CREATION*

clear all
set more off, permanently
capture log close
set scheme plottig


capture noisily cd "DEFINE"


global original "DEFINE"
global do "DEFINE"
global output "DEFINE"
global aux "DEFINE"

*Original dataset - direction where all original datasets are saved

global dir1 "DEFINE"

*Manipulated data will be stored here:

global data "DEFINE"

*******************************************************************
* Data preparation: Merging of waves and data files
*******************************************************************
*******************************************************************

* Merge all BHPS datasets into one in long format
*********************************************
foreach wave in a b c d e f g h i j k l m n o p q r {
	use "$dir1/`wave'indresp", clear
	rename `wave'* *
	capture rename id pid
	gen wave = strpos("abcdefghijklmnopqr","`wave'")
	save "${aux}/ind_junk`wave'", replace
}
//  append rest of the waves
foreach wave in a b c d e f g h i j k l m n o p q {
	append using "${aux}/ind_junk`wave'"
}

* Selection of variables
keep pid wave hid mastat plbornc age sex hgsex isced orgmb orgab tuin1 tujbpl prjbft jbft jbhas jboff jboffy jbsemp jbstat jbterm jbterm1 jbterm2 jsbgd jsbgm jsbgy cjsbgd cjsbgm cjsbgy jsbgy4 cjsbgy4 cjsten nemst jbisco jbiscon jbhrs jbot jbbg*  jbgold jlgold magold mrjgold pagold fimn fiyr jlisco jliscon mrjisco mrjiscn jsboss jssize jbsect oppol1 oppol2 oppol3 oppol4 oprlg1 oprlg2 oprlg3 doi* 
opsoca opsocb opsocc opsocd opsoce opsocf opfama opfamb opfamc opfamd opfame opfamf opfamg opfamh opfami opfamr vote1 vote2 vote3 vote4 vote5 vote6 vote vote7 vote8 orgaa orgma orga* orgm*

* Add information on parental occupation from xwavedat (information constant for individuals accross time)

merge m:1 pid using "$dir1/xwavedat.dta"

keep if _merge==3
drop race racel j1soc j1none j1semp j1boss j1mngr lcoh coh1bm coh1by coh1mr nmar lmar1m lmar1y lprnt lnprnt ch1bm ch1by school scend sctype scnow fetype fenow feend bwtxp bwtel bwtwk bwtkn bwtlb bwtoz  bwtgm bwtg5 paseg pagold pargsc pacssm pacssf pahgs pasec maseg magold margsc macssm macssf mahgs masec j1seg j1gold j1rgsc j1isco j1cssm j1cssf j1hgs j1sec j1iscon _merge

numlabel citzn1 citzn2, add

gen british_national=1 if citzn1==6 | citzn2==6
recode british_national (.=0)
tab british_national

describe
compress
save "${aux}/ind_long_clean", replace
duplicates report pid
duplicates report pid wave

foreach wave in a b c d e f g h i j k l m n o p q r {
	erase "${aux}/ind_junk`wave'.dta"
	}

	
********************************************************************************
***** Variable management in BHPS

use "${aux}/ind_long_clean", clear

tab sex
tab sex hgsex
replace sex= hgsex if sex==-7
tab sex hgsex

recode sex (2=0), gen(male)

recode mastat (-2/0=.) (98=.) (1/2=1 "married/partnership") (3=3 "other") (4=2 "divorced/separated") (5=2) (6=3) (7=1) (8=2) (9=2) (10=3), gen(civsta_3)
tab civsta_3

recode age (-9=.)

recode jbiscon (-9/-1=.)
recode jbsemp (-9/-1=.)
recode jssize (-9/-1=.)
recode jsboss (-9/-1=.)

recode jbhas(-9 -2 -1=.)

recode jboff (-9/-1=.)

tab jbiscon jboff, m

****************************************************************************************
* Respondent's Oesch class position
* Recode and create variables used to construct class variable for respondents
****************************************************************************************

tab jbiscon
recode jbiscon (missing=-9), copyrest gen(isco_mainjob)
label variable isco_mainjob "Current occupation of respondent - isco88 4-digit"
tab isco_mainjob

**** Recode employment status for respondents

tab jbsemp

recode jbsemp (missing=9), copyrest gen(emplrel_r)

label define emplrel_r ///
1 "Employee" ///
2 "Self-employed" ///
9 "Missing"
label value emplrel_r emplrel_r
tab emplrel_r

tab jssize
replace jssize=0 if jsboss==2
recode jssize (0=0)(1/2=1)(3/11=2), gen(emplno_r)
label define emplno_r ///
0 "0 employees" ///
1 "1-9 employees" ///
2 "10+ employees"
label value emplno_r emplno_r
tab emplno_r

gen selfem_mainjob=.
replace selfem_mainjob=1 if emplrel_r==1 | emplrel_r==9
replace selfem_mainjob=2 if emplrel_r==2 & emplno_r==0
replace selfem_mainjob=2 if emplrel_r==3
replace selfem_mainjob=3 if emplrel_r==2 & emplno_r==1
replace selfem_mainjob=4 if emplrel_r==2 & emplno_r==2
label variable selfem_mainjob "Employment status for respondants"
label define selfem_mainjob ///
1 "Not self-employed" ///
2 "Self-empl without employees" ///
3 "Self-empl with 1-9 employees" ///
4 "Self-empl with 10 or more"
label value selfem_mainjob selfem_mainjob
tab selfem_mainjob


gen class16_r = -9

* Large employers (1)

replace class16_r=1 if selfem_mainjob==4


* Self-employed professionals (2)

replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco_mainjob >= 2000 & isco_mainjob <= 2229) 
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco_mainjob >= 2300 & isco_mainjob <= 2470)

* Small business owners with employees (3)

replace class16_r=3 if (selfem_mainjob==3) & (isco_mainjob >= 1000 & isco_mainjob <= 1999)
replace class16_r=3 if (selfem_mainjob==3) & (isco_mainjob >= 3000 & isco_mainjob <= 9333)
replace class16_r=3 if (selfem_mainjob==3) & (isco_mainjob == 2230)

* Small business owners without employees (4)

replace class16_r=4 if (selfem_mainjob==2) & (isco_mainjob >= 1000 & isco_mainjob <= 1999)
replace class16_r=4 if (selfem_mainjob==2) & (isco_mainjob >= 3000 & isco_mainjob <= 9333)
replace class16_r=4 if (selfem_mainjob==2) & (isco_mainjob == 2230)

* Technical experts (5)

replace class16_r=5 if (selfem_mainjob==1) & (isco_mainjob >= 2100 & isco_mainjob <= 2213)

* Technicians (6)

replace class16_r=6 if (selfem_mainjob==1) & (isco_mainjob >= 3100 & isco_mainjob <= 3152)
replace class16_r=6 if (selfem_mainjob==1) & (isco_mainjob >= 3210 & isco_mainjob <= 3213)
replace class16_r=6 if (selfem_mainjob==1) & (isco_mainjob == 3434)

* Skilled manual (7)

replace class16_r=7 if (selfem_mainjob==1) & (isco_mainjob >= 6000 & isco_mainjob <= 7442)
replace class16_r=7 if (selfem_mainjob==1) & (isco_mainjob >= 8310 & isco_mainjob <= 8312)
replace class16_r=7 if (selfem_mainjob==1) & (isco_mainjob >= 8324 & isco_mainjob <= 8330)
replace class16_r=7 if (selfem_mainjob==1) & (isco_mainjob >= 8332 & isco_mainjob <= 8340)

* Low-skilled manual (8)

replace class16_r=8 if (selfem_mainjob==1) & (isco_mainjob >= 8000 & isco_mainjob <= 8300)
replace class16_r=8 if (selfem_mainjob==1) & (isco_mainjob >= 8320 & isco_mainjob <= 8321)
replace class16_r=8 if (selfem_mainjob==1) & (isco_mainjob == 8331)
replace class16_r=8 if (selfem_mainjob==1) & (isco_mainjob >= 9153 & isco_mainjob <= 9333)

* Higher-grade managers and administrators (9)

replace class16_r=9 if (selfem_mainjob==1) & (isco_mainjob >= 1000 & isco_mainjob <= 1239)
replace class16_r=9 if (selfem_mainjob==1) & (isco_mainjob >= 2400 & isco_mainjob <= 2429)
replace class16_r=9 if (selfem_mainjob==1) & (isco_mainjob == 2441)
replace class16_r=9 if (selfem_mainjob==1) & (isco_mainjob == 2470)

* Lower-grade managers and administrators (10)

replace class16_r=10 if (selfem_mainjob==1) & (isco_mainjob >= 1300 & isco_mainjob <= 1319)
replace class16_r=10 if (selfem_mainjob==1) & (isco_mainjob >= 3400 & isco_mainjob <= 3433)
replace class16_r=10 if (selfem_mainjob==1) & (isco_mainjob >= 3440 & isco_mainjob <= 3450)

* Skilled clerks (11)

replace class16_r=11 if (selfem_mainjob==1) & (isco_mainjob >= 4000 & isco_mainjob <= 4112)
replace class16_r=11 if (selfem_mainjob==1) & (isco_mainjob >= 4114 & isco_mainjob <= 4210)
replace class16_r=11 if (selfem_mainjob==1) & (isco_mainjob >= 4212 & isco_mainjob <= 4222)

* Unskilled clerks (12)

replace class16_r=12 if (selfem_mainjob==1) & (isco_mainjob == 4113)
replace class16_r=12 if (selfem_mainjob==1) & (isco_mainjob == 4211)
replace class16_r=12 if (selfem_mainjob==1) & (isco_mainjob == 4223)

* Socio-cultural professionals (13)

replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob >= 2220 &  isco_mainjob <= 2229)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob >= 2300 &  isco_mainjob <= 2320)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob >= 2340 &  isco_mainjob <= 2359)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob >= 2430 &  isco_mainjob <= 2440)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob >= 2442 &  isco_mainjob <= 2443)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob == 2445)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob == 2451)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob == 2460)

* Socio-cultural semi-professionals (14)

replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 2230)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 2330 & isco_mainjob <= 2332)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 2444)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 2446 & isco_mainjob <= 2450)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 2452 & isco_mainjob <= 2455)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 3200)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 3220 & isco_mainjob <= 3224)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 3226)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 3229 & isco_mainjob <= 3340)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 3460 & isco_mainjob <= 3472)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 3480)

* Skilled service (15)

replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob == 3225)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob >= 3227 & isco_mainjob <= 3228)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob >= 3473 & isco_mainjob <= 3475)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob >= 5000 & isco_mainjob <= 5113)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob == 5122)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob >= 5131 & isco_mainjob <= 5132)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob >= 5140 & isco_mainjob <= 5141)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob == 5143)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob >= 5160 & isco_mainjob <= 5220)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob == 8323)

* Low-skilled service (16)

replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob >= 5120 & isco_mainjob <= 5121)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob >= 5123 & isco_mainjob <= 5130)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob >= 5133 & isco_mainjob <= 5139)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob == 5142)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob == 5149)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob == 5230)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob == 8322)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob >= 9100 &  isco_mainjob <= 9152)

mvdecode class16_r, mv(-9)
label variable class16_r "Respondent's Oesch class position - 16 classes"
label define class16_r ///
1 "Large employers" ///
2 "Self-employed professionals" ///
3 "Small business owners with employees" ///
4 "Small business owners without employees" ///
5 "Technical experts" ///
6 "Technicians" ///
7 "Skilled manual" ///
8 "Low-skilled manual" ///
9 "Higher-grade managers and administrators" ///
10 "Lower-grade managers and administrators" ///
11 "Skilled clerks" ///
12 "Unskilled clerks" ///
13 "Socio-cultural professionals" ///
14 "Socio-cultural semi-professionals" ///
15 "Skilled service" ///
16 "Low-skilled service"
label value class16_r class16_r
tab class16_r

recode class16_r (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8_r)
label variable class8_r "Respondent's Oesch class position - 8 classes"
label define class8_r ///
1 "Self-employed professionals and large employers" ///
2 "Small business owners" ///
3 "Technical (semi-)professionals" ///
4 "Production workers" ///
5 "(Associate) managers" ///
6 "Clerks" ///
7 "Socio-cultural (semi-)professionals" ///
8 "Service workers"
label value class8_r class8_r
tab class8_r

recode class16_r (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5), gen(class5_r)
label variable class5_r "Respondent's Oesch class position - 5 classes"
label define  class5_r ///
1 "Higher-grade service class" ///
2 "Lower-grade service class" ///
3 "Small business owners" ///
4 "Skilled workers" ///
5 "Unskilled workers"
label value class5_r class5_r
tab class5_r


****************************************************************************************
* Parental Oesch class position
* Recode and create variables used to construct class variable for parents
****************************************************************************************

recode pasemp (-9/0=.), gen(selfemp_fa)

recode paiscon (-9/0=.), gen(isco_father)
recode selfemp_fa (.=1) if isco_father!=.

gen selfem_father=.
replace selfem_father=1 if selfemp_fa==1
replace selfem_father=2 if selfemp_fa==2 & paboss!=2
replace selfem_father=3 if selfemp_fa==2 & paboss==2
label variable selfem_father "Employment status for fathers"
label define selfem_father ///
1 "Not self-employed" ///
2 "Self-empl without employees" ///
3 "Self-empl with employees"
label value selfem_father selfem_father
tab selfem_father

gen class16_father = -9

* Self-employed professionals (2)

replace class16_father=2 if (selfem_father==2 | selfem_father==3) & (isco_father >= 2000 & isco_father <= 2229) 
replace class16_father=2 if (selfem_father==2 | selfem_father==3) & (isco_father >= 2300 & isco_father <= 2470)

* Business owners with employees (3)

replace class16_father=3 if (selfem_father==3) & (isco_father >= 1000 & isco_father <= 1999)
replace class16_father=3 if (selfem_father==3) & (isco_father >= 3000 & isco_father <= 9333)
replace class16_father=3 if (selfem_father==3) & (isco_father == 2230)

* Small business owners without employees (4)

replace class16_father=4 if (selfem_father==2) & (isco_father >= 1000 & isco_father <= 1999)
replace class16_father=4 if (selfem_father==2) & (isco_father >= 3000 & isco_father <= 9333)
replace class16_father=4 if (selfem_father==2) & (isco_father == 2230)

* Technical experts (5)

replace class16_father=5 if (selfem_father==1) & (isco_father >= 2100 & isco_father <= 2213)

* Technicians (6)

replace class16_father=6 if (selfem_father==1) & (isco_father >= 3100 & isco_father <= 3152)
replace class16_father=6 if (selfem_father==1) & (isco_father >= 3210 & isco_father <= 3213)
replace class16_father=6 if (selfem_father==1) & (isco_father == 3434)

* Skilled manual (7)

replace class16_father=7 if (selfem_father==1) & (isco_father >= 6000 & isco_father <= 7442)
replace class16_father=7 if (selfem_father==1) & (isco_father >= 8310 & isco_father <= 8312)
replace class16_father=7 if (selfem_father==1) & (isco_father >= 8324 & isco_father <= 8330)
replace class16_father=7 if (selfem_father==1) & (isco_father >= 8332 & isco_father <= 8340)

* Low-skilled manual (8)

replace class16_father=8 if (selfem_father==1) & (isco_father >= 8000 & isco_father <= 8300)
replace class16_father=8 if (selfem_father==1) & (isco_father >= 8320 & isco_father <= 8321)
replace class16_father=8 if (selfem_father==1) & (isco_father == 8331)
replace class16_father=8 if (selfem_father==1) & (isco_father >= 9153 & isco_father <= 9333)

* Higher-grade managers and administrators (9)

replace class16_father=9 if (selfem_father==1) & (isco_father >= 1000 & isco_father <= 1239)
replace class16_father=9 if (selfem_father==1) & (isco_father >= 2400 & isco_father <= 2429)
replace class16_father=9 if (selfem_father==1) & (isco_father == 2441)
replace class16_father=9 if (selfem_father==1) & (isco_father == 2470)

* Lower-grade managers and administrators (10)

replace class16_father=10 if (selfem_father==1) & (isco_father >= 1300 & isco_father <= 1319)
replace class16_father=10 if (selfem_father==1) & (isco_father >= 3400 & isco_father <= 3433)
replace class16_father=10 if (selfem_father==1) & (isco_father >= 3440 & isco_father <= 3450)

* Skilled clerks (11)

replace class16_father=11 if (selfem_father==1) & (isco_father >= 4000 & isco_father <= 4112)
replace class16_father=11 if (selfem_father==1) & (isco_father >= 4114 & isco_father <= 4210)
replace class16_father=11 if (selfem_father==1) & (isco_father >= 4212 & isco_father <= 4222)

* Unskilled clerks (12)

replace class16_father=12 if (selfem_father==1) & (isco_father == 4113)
replace class16_father=12 if (selfem_father==1) & (isco_father == 4211)
replace class16_father=12 if (selfem_father==1) & (isco_father == 4223)

* Socio-cultural professionals (13)

replace class16_father=13 if (selfem_father==1) & (isco_father >= 2220 &  isco_father <= 2229)
replace class16_father=13 if (selfem_father==1) & (isco_father >= 2300 &  isco_father <= 2320)
replace class16_father=13 if (selfem_father==1) & (isco_father >= 2340 &  isco_father <= 2359)
replace class16_father=13 if (selfem_father==1) & (isco_father >= 2430 &  isco_father <= 2440)
replace class16_father=13 if (selfem_father==1) & (isco_father >= 2442 &  isco_father <= 2443)
replace class16_father=13 if (selfem_father==1) & (isco_father == 2445)
replace class16_father=13 if (selfem_father==1) & (isco_father == 2451)
replace class16_father=13 if (selfem_father==1) & (isco_father == 2460)

* Socio-cultural semi-professionals (14)

replace class16_father=14 if (selfem_father==1) & (isco_father == 2230)
replace class16_father=14 if (selfem_father==1) & (isco_father >= 2330 & isco_father <= 2332)
replace class16_father=14 if (selfem_father==1) & (isco_father == 2444)
replace class16_father=14 if (selfem_father==1) & (isco_father >= 2446 & isco_father <= 2450)
replace class16_father=14 if (selfem_father==1) & (isco_father >= 2452 & isco_father <= 2455)
replace class16_father=14 if (selfem_father==1) & (isco_father == 3200)
replace class16_father=14 if (selfem_father==1) & (isco_father >= 3220 & isco_father <= 3224)
replace class16_father=14 if (selfem_father==1) & (isco_father == 3226)
replace class16_father=14 if (selfem_father==1) & (isco_father >= 3229 & isco_father <= 3340)
replace class16_father=14 if (selfem_father==1) & (isco_father >= 3460 & isco_father <= 3472)
replace class16_father=14 if (selfem_father==1) & (isco_father == 3480)

* Skilled service (15)

replace class16_father=15 if (selfem_father==1) & (isco_father == 3225)
replace class16_father=15 if (selfem_father==1) & (isco_father >= 3227 & isco_father <= 3228)
replace class16_father=15 if (selfem_father==1) & (isco_father >= 3473 & isco_father <= 3475)
replace class16_father=15 if (selfem_father==1) & (isco_father >= 5000 & isco_father <= 5113)
replace class16_father=15 if (selfem_father==1) & (isco_father == 5122)
replace class16_father=15 if (selfem_father==1) & (isco_father >= 5131 & isco_father <= 5132)
replace class16_father=15 if (selfem_father==1) & (isco_father >= 5140 & isco_father <= 5141)
replace class16_father=15 if (selfem_father==1) & (isco_father == 5143)
replace class16_father=15 if (selfem_father==1) & (isco_father >= 5160 & isco_father <= 5220)
replace class16_father=15 if (selfem_father==1) & (isco_father == 8323)

* Low-skilled service (16)

replace class16_father=16 if (selfem_father==1) & (isco_father >= 5120 & isco_father <= 5121)
replace class16_father=16 if (selfem_father==1) & (isco_father >= 5123 & isco_father <= 5130)
replace class16_father=16 if (selfem_father==1) & (isco_father >= 5133 & isco_father <= 5139)
replace class16_father=16 if (selfem_father==1) & (isco_father == 5142)
replace class16_father=16 if (selfem_father==1) & (isco_father == 5149)
replace class16_father=16 if (selfem_father==1) & (isco_father == 5230)
replace class16_father=16 if (selfem_father==1) & (isco_father == 8322)
replace class16_father=16 if (selfem_father==1) & (isco_father >= 9100 &  isco_father <= 9152)

mvdecode class16_father, mv(-9)
label variable class16_father "Father's Oesch class position - 16 classes"
label define class16_father ///
1 "Large employers" ///
2 "Self-employed professionals" ///
3 "Small business owners with employees" ///
4 "Small business owners without employees" ///
5 "Technical experts" ///
6 "Technicians" ///
7 "Skilled manual" ///
8 "Low-skilled manual" ///
9 "Higher-grade managers and administrators" ///
10 "Lower-grade managers and administrators" ///
11 "Skilled clerks" ///
12 "Unskilled clerks" ///
13 "Socio-cultural professionals" ///
14 "Socio-cultural semi-professionals" ///
15 "Skilled service" ///
16 "Low-skilled service"
label value class16_father class16_father
tab class16_father

recode class16_father (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8_father)
label variable class8_father "Father's Oesch class position - 8 classes"
label define class8_father ///
1 "Self-employed professionals" ///
2 "Business owners" ///
3 "Technical (semi-)professionals" ///
4 "Production workers" ///
5 "(Associate) managers" ///
6 "Clerks" ///
7 "Socio-cultural (semi-)professionals" ///
8 "Service workers"
label value class8_father class8_father
tab class8_father

recode class16_father (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5), gen(class5_father)
label variable class5_father "Father's Oesch class position - 5 classes"
label define  class5_father ///
1 "Higher-grade service class" ///
2 "Lower-grade service class" ///
3 "Small business owners" ///
4 "Skilled workers" ///
5 "Unskilled workers"
label value class5_father class5_father
tab class5_father


recode masemp (-9/0=.), gen(selfemp_ma)

recode maiscon (-9/0=.), gen(isco_mother)
recode selfemp_ma (.=1) if isco_mother!=.

gen selfem_mother=.
replace selfem_mother=1 if selfemp_ma==1
replace selfem_mother=2 if selfemp_ma==2 & maboss!=2
replace selfem_mother=3 if selfemp_ma==2 & maboss==2
label variable selfem_mother "Employment status for mothers"
label define selfem_mother ///
1 "Not self-employed" ///
2 "Self-empl without employees" ///
3 "Self-empl with employees"
label value selfem_mother selfem_mother
tab selfem_mother


gen class16_mother = -9

* Self-employed professionals (2)

replace class16_mother=2 if (selfem_mother==2 | selfem_mother==3) & (isco_mother >= 2000 & isco_mother <= 2229) 
replace class16_mother=2 if (selfem_mother==2 | selfem_mother==3) & (isco_mother >= 2300 & isco_mother <= 2470)

* Business owners with employees (3)

replace class16_mother=3 if (selfem_mother==3) & (isco_mother >= 1000 & isco_mother <= 1999)
replace class16_mother=3 if (selfem_mother==3) & (isco_mother >= 3000 & isco_mother <= 9333)
replace class16_mother=3 if (selfem_mother==3) & (isco_mother == 2230)

* Small business owners without employees (4)

replace class16_mother=4 if (selfem_mother==2) & (isco_mother >= 1000 & isco_mother <= 1999)
replace class16_mother=4 if (selfem_mother==2) & (isco_mother >= 3000 & isco_mother <= 9333)
replace class16_mother=4 if (selfem_mother==2) & (isco_mother == 2230)

* Technical experts (5)

replace class16_mother=5 if (selfem_mother==1) & (isco_mother >= 2100 & isco_mother <= 2213)

* Technicians (6)

replace class16_mother=6 if (selfem_mother==1) & (isco_mother >= 3100 & isco_mother <= 3152)
replace class16_mother=6 if (selfem_mother==1) & (isco_mother >= 3210 & isco_mother <= 3213)
replace class16_mother=6 if (selfem_mother==1) & (isco_mother == 3434)

* Skilled manual (7)

replace class16_mother=7 if (selfem_mother==1) & (isco_mother >= 6000 & isco_mother <= 7442)
replace class16_mother=7 if (selfem_mother==1) & (isco_mother >= 8310 & isco_mother <= 8312)
replace class16_mother=7 if (selfem_mother==1) & (isco_mother >= 8324 & isco_mother <= 8330)
replace class16_mother=7 if (selfem_mother==1) & (isco_mother >= 8332 & isco_mother <= 8340)

* Low-skilled manual (8)

replace class16_mother=8 if (selfem_mother==1) & (isco_mother >= 8000 & isco_mother <= 8300)
replace class16_mother=8 if (selfem_mother==1) & (isco_mother >= 8320 & isco_mother <= 8321)
replace class16_mother=8 if (selfem_mother==1) & (isco_mother == 8331)
replace class16_mother=8 if (selfem_mother==1) & (isco_mother >= 9153 & isco_mother <= 9333)

* Higher-grade managers and administrators (9)

replace class16_mother=9 if (selfem_mother==1) & (isco_mother >= 1000 & isco_mother <= 1239)
replace class16_mother=9 if (selfem_mother==1) & (isco_mother >= 2400 & isco_mother <= 2429)
replace class16_mother=9 if (selfem_mother==1) & (isco_mother == 2441)
replace class16_mother=9 if (selfem_mother==1) & (isco_mother == 2470)

* Lower-grade managers and administrators (10)

replace class16_mother=10 if (selfem_mother==1) & (isco_mother >= 1300 & isco_mother <= 1319)
replace class16_mother=10 if (selfem_mother==1) & (isco_mother >= 3400 & isco_mother <= 3433)
replace class16_mother=10 if (selfem_mother==1) & (isco_mother >= 3440 & isco_mother <= 3450)

* Skilled clerks (11)

replace class16_mother=11 if (selfem_mother==1) & (isco_mother >= 4000 & isco_mother <= 4112)
replace class16_mother=11 if (selfem_mother==1) & (isco_mother >= 4114 & isco_mother <= 4210)
replace class16_mother=11 if (selfem_mother==1) & (isco_mother >= 4212 & isco_mother <= 4222)

* Unskilled clerks (12)

replace class16_mother=12 if (selfem_mother==1) & (isco_mother == 4113)
replace class16_mother=12 if (selfem_mother==1) & (isco_mother == 4211)
replace class16_mother=12 if (selfem_mother==1) & (isco_mother == 4223)

* Socio-cultural professionals (13)

replace class16_mother=13 if (selfem_mother==1) & (isco_mother >= 2220 &  isco_mother <= 2229)
replace class16_mother=13 if (selfem_mother==1) & (isco_mother >= 2300 &  isco_mother <= 2320)
replace class16_mother=13 if (selfem_mother==1) & (isco_mother >= 2340 &  isco_mother <= 2359)
replace class16_mother=13 if (selfem_mother==1) & (isco_mother >= 2430 &  isco_mother <= 2440)
replace class16_mother=13 if (selfem_mother==1) & (isco_mother >= 2442 &  isco_mother <= 2443)
replace class16_mother=13 if (selfem_mother==1) & (isco_mother == 2445)
replace class16_mother=13 if (selfem_mother==1) & (isco_mother == 2451)
replace class16_mother=13 if (selfem_mother==1) & (isco_mother == 2460)

* Socio-cultural semi-professionals (14)

replace class16_mother=14 if (selfem_mother==1) & (isco_mother == 2230)
replace class16_mother=14 if (selfem_mother==1) & (isco_mother >= 2330 & isco_mother <= 2332)
replace class16_mother=14 if (selfem_mother==1) & (isco_mother == 2444)
replace class16_mother=14 if (selfem_mother==1) & (isco_mother >= 2446 & isco_mother <= 2450)
replace class16_mother=14 if (selfem_mother==1) & (isco_mother >= 2452 & isco_mother <= 2455)
replace class16_mother=14 if (selfem_mother==1) & (isco_mother == 3200)
replace class16_mother=14 if (selfem_mother==1) & (isco_mother >= 3220 & isco_mother <= 3224)
replace class16_mother=14 if (selfem_mother==1) & (isco_mother == 3226)
replace class16_mother=14 if (selfem_mother==1) & (isco_mother >= 3229 & isco_mother <= 3340)
replace class16_mother=14 if (selfem_mother==1) & (isco_mother >= 3460 & isco_mother <= 3472)
replace class16_mother=14 if (selfem_mother==1) & (isco_mother == 3480)

* Skilled service (15)

replace class16_mother=15 if (selfem_mother==1) & (isco_mother == 3225)
replace class16_mother=15 if (selfem_mother==1) & (isco_mother >= 3227 & isco_mother <= 3228)
replace class16_mother=15 if (selfem_mother==1) & (isco_mother >= 3473 & isco_mother <= 3475)
replace class16_mother=15 if (selfem_mother==1) & (isco_mother >= 5000 & isco_mother <= 5113)
replace class16_mother=15 if (selfem_mother==1) & (isco_mother == 5122)
replace class16_mother=15 if (selfem_mother==1) & (isco_mother >= 5131 & isco_mother <= 5132)
replace class16_mother=15 if (selfem_mother==1) & (isco_mother >= 5140 & isco_mother <= 5141)
replace class16_mother=15 if (selfem_mother==1) & (isco_mother == 5143)
replace class16_mother=15 if (selfem_mother==1) & (isco_mother >= 5160 & isco_mother <= 5220)
replace class16_mother=15 if (selfem_mother==1) & (isco_mother == 8323)

* Low-skilled service (16)

replace class16_mother=16 if (selfem_mother==1) & (isco_mother >= 5120 & isco_mother <= 5121)
replace class16_mother=16 if (selfem_mother==1) & (isco_mother >= 5123 & isco_mother <= 5130)
replace class16_mother=16 if (selfem_mother==1) & (isco_mother >= 5133 & isco_mother <= 5139)
replace class16_mother=16 if (selfem_mother==1) & (isco_mother == 5142)
replace class16_mother=16 if (selfem_mother==1) & (isco_mother == 5149)
replace class16_mother=16 if (selfem_mother==1) & (isco_mother == 5230)
replace class16_mother=16 if (selfem_mother==1) & (isco_mother == 8322)
replace class16_mother=16 if (selfem_mother==1) & (isco_mother >= 9100 &  isco_mother <= 9152)

mvdecode class16_mother, mv(-9)
label variable class16_mother "Mother's Oesch class position - 16 classes"
label define class16_mother ///
1 "Large employers" ///
2 "Self-employed professionals" ///
3 "Small business owners with employees" ///
4 "Small business owners without employees" ///
5 "Technical experts" ///
6 "Technicians" ///
7 "Skilled manual" ///
8 "Low-skilled manual" ///
9 "Higher-grade managers and administrators" ///
10 "Lower-grade managers and administrators" ///
11 "Skilled clerks" ///
12 "Unskilled clerks" ///
13 "Socio-cultural professionals" ///
14 "Socio-cultural semi-professionals" ///
15 "Skilled service" ///
16 "Low-skilled service"
label value class16_mother class16_mother
tab class16_mother

recode class16_mother (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8_mother)
label variable class8_mother "Mother's Oesch class position - 8 classes"
label define class8_mother ///
1 "Self-employed professionals" ///
2 "Business owners" ///
3 "Technical (semi-)professionals" ///
4 "Production workers" ///
5 "(Associate) managers" ///
6 "Clerks" ///
7 "Socio-cultural (semi-)professionals" ///
8 "Service workers"
label value class8_mother class8_mother
tab class8_mother

recode class16_mother (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5), gen(class5_mother)
label variable class5_mother "Mother's Oesch class position - 5 classes"
label define  class5_mother ///
1 "Higher-grade service class" ///
2 "Lower-grade service class" ///
3 "Small business owners" ///
4 "Skilled workers" ///
5 "Unskilled workers"
label value class5_mother class5_mother
tab class5_mother

gen class16_parent= class16_father
replace class16_parent= class16_mother if class16_father==.
label value class16_parent class16_father

recode class16_parent (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8_parent)
label variable class8_parent "Parental Oesch class position - 8 classes"
label value class8_parent class8_mother
tab class8_parent, m

recode class16_parent (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5), gen(class5_parent)
label variable class5_parent "Parental Oesch class position - 5 classes"
label value class5_parent class5_mother
tab class5_parent, m

*****
***** Party preference in BHPS

gen closest_party = vote4
recode closest_party (-9/-2=.) (97=.) (8=.) (10=.)

gen tomorrow_party = vote3
recode tomorrow_party (-9/-2=.)

gen pref_party=closest_party
replace pref_party=tomorrow_party if closest_party==.

recode pref_party (-1=0) (1=0) (2=1) (3/97=0), gen(pref_lab)

gen closest_left = vote4
recode closest_left (-9/-2=.) (-1=0) (1=0) (2=1) (3=0) (4=1) (5=0) (6=1) (7=0) (8=0) (10=0) (12=0) (13=1) (14=0) (15=0) (16=1) (17=0) (97=0)

gen tomorrow_left = vote3
recode tomorrow_left (-9/-2=.) (-1=0) (1=0) (2=1) (3=0) (4=1) (5=0) (6=1) (7=0) (8=0) (10=0) (11=0) (12=0) (13=1) (14=0) (15=0) (16=1) (17=0) (97=0)

gen pref_left=closest_left
tab closest_left tomorrow_left, m 
replace pref_left=tomorrow_left if closest_left==.

gen closest_left_ng = vote4
recode closest_left_ng (-9/-2=.) (-1=0) (1=0) (2=1) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (10=0) (12=0) (13=1) (14=0) (15=0) (16=1) (17=0) (97=0)

gen tomorrow_left_ng = vote3
recode tomorrow_left_ng (-9/-2=.) (-1=0) (1=0) (2=1) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (10=0) (11=0) (12=0) (13=1) (14=0) (15=0) (16=1) (17=0) (97=0)

gen pref_left_ng=closest_left_ng
tab closest_left_ng tomorrow_left_ng, m 
replace pref_left_ng=tomorrow_left_ng if closest_left_ng==.


** Prepare BHPS to me merged with UKHLS

save "$aux/ind_long_bhps.dta", replace

preserve
use "$dir1\UKHLS\ukhls_wx\xwavedat.dta", clear
drop if xwdat_dv==1
keep pidp pid xwdat_dv bornuk_dv
save "$aux/xwave_selection.dta", replace
restore

merge m:1 pid using "$aux/xwave_selection.dta"
keep if _merge==3

save "$aux/ind_long_bhps_pid.dta", replace


********************************************************************************
********************************************************************************
** UKHLS data - coding and preparation

clear all

// assign global macro to refer to Understanding Society data
global ukhls "DEFINE"

global UKHLSwaves_bh "b c d e f g h i j" 
global UKHLSno 10	// number of waves of UKHLS data								 

set maxvar 10000

// loop through the relevant waves of Understanding Society
foreach w of global UKHLSwaves_bh {

	// find the wave number
	local waveno=strpos("abcdefghijklmnopqrstuvwxyz","`w'")
	
	// open the individual level file for that wave
	use "$ukhls/UKHLS/ukhls_w`waveno'/`w'_indresp", clear
	
	// keep the individual if they have a pid - ie were part of BHPS
	// individuals have pid==-8 (inapplicable) if they were not part of BHPS
	keep if pid>0
	
	// drop the pid variable
	drop pid
	
	// remove the wave prefix
	rename `w'_* *

	// generate a variable which records the wave number + 17 
	// - treating wave 2 ukhls as wave 19 of bhps
	gen wave=`waveno'+17
	
	// save the file for future use
	save tmp_`w'_indresp, replace
}

use "$aux/ind_long_bhps_pid.dta", clear

// loop through the waves of ukhls from Wave 2
foreach w of global UKHLSwaves_bh {
	
	// append each file in turn
	append using tmp_`w'_indresp
}

// create labels for the wave variable
// loop through the waves of bhps
foreach n of numlist 1/18 {

	// add a label for each wave number in turn
	lab def wave `n' "BHPS Wave `n'", modify
}

// loop through the waves of ukhls 
foreach n of numlist 2/$UKHLSno {
	local waveref=`n'+17
	lab def wave `waveref' "UKHLS Wave `n'", modify
}

lab val wave wave

// save the file containing all waves
compress
save "$original/bhps_ukhls.dta", replace

foreach w of global UKHLSwaves_bh {
	erase tmp_`w'_indresp.dta
}

}
******************************************************************************************
******** Merge with xwavedat for parental information

clear

set maxvar 10000

use "$original/bhps_ukhls.dta", clear

drop _merge maju masoc90_cc masoc00_cc masoc10_cc paju pasoc90_cc pasoc00_cc pasoc10_cc bornuk_dv

label drop maju paju

capture noisily merge m:1 pidp using "$dir1\UKHLS\ukhls_wx\xwavedat.dta", keepusing(birthy bornuk_dv maju masoc90_cc masoc00_cc masoc10_cc paju pasoc90_cc pasoc00_cc pasoc10_cc pagold magold)

keep if _merge==3
drop _merge

preserve
collapse (max) class8_parent class8_mother class8_father, by(pidp)
save "$aux/parentalclass_frombhps.dta", replace
use "$aux/parentalclass_frombhps.dta", clear
rename class8_parent class8_parent_all
rename class8_mother class8_mother_all
rename class8_father class8_father_all
save "$aux/parentalclass_frombhps.dta", replace
restore

merge m:1 pidp using "$aux/parentalclass_frombhps.dta", keepusing(class8_parent_all class8_mother_all class8_father_all)

label values class8_parent_all class8_father
label values class8_mother_all class8_father
label values class8_father_all class8_father

* For how many respondents do we have information about father occupation from ukhls but not from bhps
tab pasoc90_cc wave if class8_parent_all ==. & wave>18, nol
tab pasoc00_cc wave if class8_parent_all ==. & wave>18, nol
tab pasoc10_cc wave if class8_parent_all ==. & wave>18, nol

** Assign parental class from soc 00 and 10 for those for which it is missing

gen class16_father_soc=.
replace class16_father_soc=0 if class16_parent==.

recode class16_father_soc (0=9) if pasoc10_cc==111
recode class16_father_soc (0=9) if pasoc10_cc==112
recode class16_father_soc (0=9) if pasoc10_cc==113
recode class16_father_soc (0=9) if pasoc10_cc==115
recode class16_father_soc (0=9) if pasoc10_cc==116
recode class16_father_soc (0=9) if pasoc10_cc==117
recode class16_father_soc (0=9) if pasoc10_cc==118
recode class16_father_soc (0=10) if pasoc10_cc==119
recode class16_father_soc (0=10) if pasoc10_cc==121
recode class16_father_soc (0=10) if pasoc10_cc==122
recode class16_father_soc (0=11) if pasoc10_cc==124
recode class16_father_soc (0=10) if pasoc10_cc==125
recode class16_father_soc (0=5) if pasoc10_cc==211
recode class16_father_soc (0=5) if pasoc10_cc==212
recode class16_father_soc (0=5) if pasoc10_cc==213
recode class16_father_soc (0=5) if pasoc10_cc==214
recode class16_father_soc (0=9) if pasoc10_cc==215
recode class16_father_soc (0=14) if pasoc10_cc==221
recode class16_father_soc (0=14) if pasoc10_cc==222
recode class16_father_soc (0=14) if pasoc10_cc==223
recode class16_father_soc (0=13) if pasoc10_cc==231
recode class16_father_soc (0=9) if pasoc10_cc==241
recode class16_father_soc (0=9) if pasoc10_cc==242
recode class16_father_soc (0=5) if pasoc10_cc==243
recode class16_father_soc (0=14) if pasoc10_cc==244
recode class16_father_soc (0=14) if pasoc10_cc==245
recode class16_father_soc (0=9) if pasoc10_cc==246
recode class16_father_soc (0=9) if pasoc10_cc==247
recode class16_father_soc (0=6) if pasoc10_cc==311
recode class16_father_soc (0=6) if pasoc10_cc==312
recode class16_father_soc (0=6) if pasoc10_cc==313
recode class16_father_soc (0=6) if pasoc10_cc==321
recode class16_father_soc (0=14) if pasoc10_cc==323
recode class16_father_soc (0=15) if pasoc10_cc==331
recode class16_father_soc (0=14) if pasoc10_cc==341
recode class16_father_soc (0=14) if pasoc10_cc==342
recode class16_father_soc (0=15) if pasoc10_cc==344
recode class16_father_soc (0=6) if pasoc10_cc==351
recode class16_father_soc (0=10) if pasoc10_cc==352
recode class16_father_soc (0=10) if pasoc10_cc==353
recode class16_father_soc (0=10) if pasoc10_cc==354
recode class16_father_soc (0=6) if pasoc10_cc==355
recode class16_father_soc (0=9) if pasoc10_cc==356
recode class16_father_soc (0=11) if pasoc10_cc==411
recode class16_father_soc (0=11) if pasoc10_cc==412
recode class16_father_soc (0=11) if pasoc10_cc==413
recode class16_father_soc (0=16) if pasoc10_cc==415
recode class16_father_soc (0=11) if pasoc10_cc==416
recode class16_father_soc (0=11) if pasoc10_cc==421
recode class16_father_soc (0=7) if pasoc10_cc==511
recode class16_father_soc (0=7) if pasoc10_cc==521
recode class16_father_soc (0=7) if pasoc10_cc==522
recode class16_father_soc (0=7) if pasoc10_cc==523
recode class16_father_soc (0=7) if pasoc10_cc==524
recode class16_father_soc (0=6) if pasoc10_cc==525
recode class16_father_soc (0=7) if pasoc10_cc==531
recode class16_father_soc (0=7) if pasoc10_cc==532
recode class16_father_soc (0=6) if pasoc10_cc==533
recode class16_father_soc (0=7) if pasoc10_cc==541
recode class16_father_soc (0=7) if pasoc10_cc==542
recode class16_father_soc (0=7) if pasoc10_cc==543
recode class16_father_soc (0=7) if pasoc10_cc==544
recode class16_father_soc (0=15) if pasoc10_cc==612
recode class16_father_soc (0=15) if pasoc10_cc==613
recode class16_father_soc (0=16) if pasoc10_cc==614
recode class16_father_soc (0=15) if pasoc10_cc==621
recode class16_father_soc (0=15) if pasoc10_cc==622
recode class16_father_soc (0=16) if pasoc10_cc==623
recode class16_father_soc (0=16) if pasoc10_cc==624
recode class16_father_soc (0=15) if pasoc10_cc==711
recode class16_father_soc (0=15) if pasoc10_cc==712
recode class16_father_soc (0=15) if pasoc10_cc==713
recode class16_father_soc (0=12) if pasoc10_cc==721
recode class16_father_soc (0=11) if pasoc10_cc==722
recode class16_father_soc (0=8) if pasoc10_cc==811
recode class16_father_soc (0=7) if pasoc10_cc==812
recode class16_father_soc (0=8) if pasoc10_cc==813
recode class16_father_soc (0=8) if pasoc10_cc==814
recode class16_father_soc (0=15) if pasoc10_cc==821
recode class16_father_soc (0=7) if pasoc10_cc==822
recode class16_father_soc (0=8) if pasoc10_cc==823
recode class16_father_soc (0=8) if pasoc10_cc==911
recode class16_father_soc (0=8) if pasoc10_cc==912
recode class16_father_soc (0=8) if pasoc10_cc==913
recode class16_father_soc (0=12) if pasoc10_cc==921
recode class16_father_soc (0=16) if pasoc10_cc==923
recode class16_father_soc (0=8) if pasoc10_cc==924
recode class16_father_soc (0=8) if pasoc10_cc==925
recode class16_father_soc (0=8) if pasoc10_cc==926
recode class16_father_soc (0=16)if pasoc10_cc==927

* SOC 00
recode class16_father_soc (0=9) if pasoc00_cc==111
recode class16_father_soc (0=9) if pasoc00_cc==112
recode class16_father_soc (0=9) if pasoc00_cc==113
recode class16_father_soc (0=11) if pasoc00_cc==114
recode class16_father_soc (0=9) if pasoc00_cc==115
recode class16_father_soc (0=10) if pasoc00_cc==116
recode class16_father_soc (0=9) if pasoc00_cc==117
recode class16_father_soc (0=10) if pasoc00_cc==118
recode class16_father_soc (0=10) if pasoc00_cc==121
recode class16_father_soc (0=10) if pasoc00_cc==122
recode class16_father_soc (0=10) if pasoc00_cc==123
recode class16_father_soc (0=5) if pasoc00_cc==211
recode class16_father_soc (0=5) if pasoc00_cc==212
recode class16_father_soc (0=5) if pasoc00_cc==213
recode class16_father_soc (0=13) if pasoc00_cc==221
recode class16_father_soc (0=13) if pasoc00_cc==231
recode class16_father_soc (0=5) if pasoc00_cc==232
recode class16_father_soc (0=9) if pasoc00_cc==241
recode class16_father_soc (0=9) if pasoc00_cc==242
recode class16_father_soc (0=5) if pasoc00_cc==243
recode class16_father_soc (0=14) if pasoc00_cc==244
recode class16_father_soc (0=14) if pasoc00_cc==245
recode class16_father_soc (0=6) if pasoc00_cc==311
recode class16_father_soc (0=6) if pasoc00_cc==312
recode class16_father_soc (0=6) if pasoc00_cc==313
recode class16_father_soc (0=14) if pasoc00_cc==321
recode class16_father_soc (0=14) if pasoc00_cc==322
recode class16_father_soc (0=14) if pasoc00_cc==323
recode class16_father_soc (0=15) if pasoc00_cc==331
recode class16_father_soc (0=14) if pasoc00_cc==341
recode class16_father_soc (0=14) if pasoc00_cc==342
recode class16_father_soc (0=9) if pasoc00_cc==343
recode class16_father_soc (0=15) if pasoc00_cc==344
recode class16_father_soc (0=6) if pasoc00_cc==351
recode class16_father_soc (0=10) if pasoc00_cc==352
recode class16_father_soc (0=10) if pasoc00_cc==353
recode class16_father_soc (0=10) if pasoc00_cc==354
recode class16_father_soc (0=6) if pasoc00_cc==355
recode class16_father_soc (0=9) if pasoc00_cc==356
recode class16_father_soc (0=11) if pasoc00_cc==411
recode class16_father_soc (0=11) if pasoc00_cc==412
recode class16_father_soc (0=11) if pasoc00_cc==413
recode class16_father_soc (0=12) if pasoc00_cc==414
recode class16_father_soc (0=11) if pasoc00_cc==415
recode class16_father_soc (0=11) if pasoc00_cc==421
recode class16_father_soc (0=7) if pasoc00_cc==511
recode class16_father_soc (0=7) if pasoc00_cc==521
recode class16_father_soc (0=7) if pasoc00_cc==522
recode class16_father_soc (0=7) if pasoc00_cc==523
recode class16_father_soc (0=7) if pasoc00_cc==524
recode class16_father_soc (0=7) if pasoc00_cc==531
recode class16_father_soc (0=7) if pasoc00_cc==532
recode class16_father_soc (0=7) if pasoc00_cc==541
recode class16_father_soc (0=7) if pasoc00_cc==542
recode class16_father_soc (0=15) if pasoc00_cc==543
recode class16_father_soc (0=7) if pasoc00_cc==549
recode class16_father_soc (0=15) if pasoc00_cc==611
recode class16_father_soc (0=15) if pasoc00_cc==612
recode class16_father_soc (0=15) if pasoc00_cc==613
recode class16_father_soc (0=15) if pasoc00_cc==621
recode class16_father_soc (0=15) if pasoc00_cc==622
recode class16_father_soc (0=16) if pasoc00_cc==623
recode class16_father_soc (0=15) if pasoc00_cc==629
recode class16_father_soc (0=15) if pasoc00_cc==711
recode class16_father_soc (0=16) if pasoc00_cc==712
recode class16_father_soc (0=12) if pasoc00_cc==721
recode class16_father_soc (0=8) if pasoc00_cc==811
recode class16_father_soc (0=8) if pasoc00_cc==812
recode class16_father_soc (0=8) if pasoc00_cc==813
recode class16_father_soc (0=8) if pasoc00_cc==814
recode class16_father_soc (0=16) if pasoc00_cc==821
recode class16_father_soc (0=7) if pasoc00_cc==822
recode class16_father_soc (0=8) if pasoc00_cc==911
recode class16_father_soc (0=8) if pasoc00_cc==912
recode class16_father_soc (0=8) if pasoc00_cc==913
recode class16_father_soc (0=8) if pasoc00_cc==914
recode class16_father_soc (0=11) if pasoc00_cc==921
recode class16_father_soc (0=12) if pasoc00_cc==922
recode class16_father_soc (0=16) if pasoc00_cc==923
recode class16_father_soc (0=8) if pasoc00_cc==924
recode class16_father_soc (0=8) if pasoc00_cc==925

recode class16_father_soc (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8_father_soc)
label value class8_father_soc class8_mother
recode class8_father_soc (0=.)
tab class8_father_soc

recode class8_father_soc (3=1) if inlist(pagold, 5, 6)
recode class8_father_soc (5=1) if inlist(pagold, 5, 6)
recode class8_father_soc (7=1) if inlist(pagold, 5, 6)
recode class8_father_soc (4=1) if inlist(pagold, 5, 6)
recode class8_father_soc (6=1) if inlist(pagold, 5, 6)
recode class8_father_soc (8=1) if inlist(pagold, 5, 6)

* Code mother's class

gen class16_mother_soc=.
replace class16_mother_soc=0 if class16_parent==.

recode class16_mother_soc (0=9) if masoc10_cc==111
recode class16_mother_soc (0=9) if masoc10_cc==112
recode class16_mother_soc (0=9) if masoc10_cc==113
recode class16_mother_soc (0=9) if masoc10_cc==115
recode class16_mother_soc (0=9) if masoc10_cc==116
recode class16_mother_soc (0=9) if masoc10_cc==117
recode class16_mother_soc (0=9) if masoc10_cc==118
recode class16_mother_soc (0=10) if masoc10_cc==119
recode class16_mother_soc (0=10) if masoc10_cc==121
recode class16_mother_soc (0=10) if masoc10_cc==122
recode class16_mother_soc (0=11) if masoc10_cc==124
recode class16_mother_soc (0=10) if masoc10_cc==125
recode class16_mother_soc (0=5) if masoc10_cc==211
recode class16_mother_soc (0=5) if masoc10_cc==212
recode class16_mother_soc (0=5) if masoc10_cc==213
recode class16_mother_soc (0=5) if masoc10_cc==214
recode class16_mother_soc (0=9) if masoc10_cc==215
recode class16_mother_soc (0=14) if masoc10_cc==221
recode class16_mother_soc (0=14) if masoc10_cc==222
recode class16_mother_soc (0=14) if masoc10_cc==223
recode class16_mother_soc (0=13) if masoc10_cc==231
recode class16_mother_soc (0=9) if masoc10_cc==241
recode class16_mother_soc (0=9) if masoc10_cc==242
recode class16_mother_soc (0=5) if masoc10_cc==243
recode class16_mother_soc (0=14) if masoc10_cc==244
recode class16_mother_soc (0=14) if masoc10_cc==245
recode class16_mother_soc (0=9) if masoc10_cc==246
recode class16_mother_soc (0=9) if masoc10_cc==247
recode class16_mother_soc (0=6) if masoc10_cc==311
recode class16_mother_soc (0=6) if masoc10_cc==312
recode class16_mother_soc (0=6) if masoc10_cc==313
recode class16_mother_soc (0=6) if masoc10_cc==321
recode class16_mother_soc (0=14) if masoc10_cc==323
recode class16_mother_soc (0=15) if masoc10_cc==331
recode class16_mother_soc (0=14) if masoc10_cc==341
recode class16_mother_soc (0=14) if masoc10_cc==342
recode class16_mother_soc (0=15) if masoc10_cc==344
recode class16_mother_soc (0=6) if masoc10_cc==351
recode class16_mother_soc (0=10) if masoc10_cc==352
recode class16_mother_soc (0=10) if masoc10_cc==353
recode class16_mother_soc (0=10) if masoc10_cc==354
recode class16_mother_soc (0=6) if masoc10_cc==355
recode class16_mother_soc (0=9) if masoc10_cc==356
recode class16_mother_soc (0=11) if masoc10_cc==411
recode class16_mother_soc (0=11) if masoc10_cc==412
recode class16_mother_soc (0=11) if masoc10_cc==413
recode class16_mother_soc (0=16) if masoc10_cc==415
recode class16_mother_soc (0=11) if masoc10_cc==416
recode class16_mother_soc (0=11) if masoc10_cc==421
recode class16_mother_soc (0=7) if masoc10_cc==511
recode class16_mother_soc (0=7) if masoc10_cc==521
recode class16_mother_soc (0=7) if masoc10_cc==522
recode class16_mother_soc (0=7) if masoc10_cc==523
recode class16_mother_soc (0=7) if masoc10_cc==524
recode class16_mother_soc (0=6) if masoc10_cc==525
recode class16_mother_soc (0=7) if masoc10_cc==531
recode class16_mother_soc (0=7) if masoc10_cc==532
recode class16_mother_soc (0=6) if masoc10_cc==533
recode class16_mother_soc (0=7) if masoc10_cc==541
recode class16_mother_soc (0=7) if masoc10_cc==542
recode class16_mother_soc (0=7) if masoc10_cc==543
recode class16_mother_soc (0=7) if masoc10_cc==544
recode class16_mother_soc (0=15) if masoc10_cc==612
recode class16_mother_soc (0=15) if masoc10_cc==613
recode class16_mother_soc (0=16) if masoc10_cc==614
recode class16_mother_soc (0=15) if masoc10_cc==621
recode class16_mother_soc (0=15) if masoc10_cc==622
recode class16_mother_soc (0=16) if masoc10_cc==623
recode class16_mother_soc (0=16) if masoc10_cc==624
recode class16_mother_soc (0=15) if masoc10_cc==711
recode class16_mother_soc (0=15) if masoc10_cc==712
recode class16_mother_soc (0=15) if masoc10_cc==713
recode class16_mother_soc (0=12) if masoc10_cc==721
recode class16_mother_soc (0=11) if masoc10_cc==722
recode class16_mother_soc (0=8) if masoc10_cc==811
recode class16_mother_soc (0=7) if masoc10_cc==812
recode class16_mother_soc (0=8) if masoc10_cc==813
recode class16_mother_soc (0=8) if masoc10_cc==814
recode class16_mother_soc (0=15) if masoc10_cc==821
recode class16_mother_soc (0=7) if masoc10_cc==822
recode class16_mother_soc (0=8) if masoc10_cc==823
recode class16_mother_soc (0=8) if masoc10_cc==911
recode class16_mother_soc (0=8) if masoc10_cc==912
recode class16_mother_soc (0=8) if masoc10_cc==913
recode class16_mother_soc (0=12) if masoc10_cc==921
recode class16_mother_soc (0=16) if masoc10_cc==923
recode class16_mother_soc (0=8) if masoc10_cc==924
recode class16_mother_soc (0=8) if masoc10_cc==925
recode class16_mother_soc (0=8) if masoc10_cc==926
recode class16_mother_soc (0=16)if masoc10_cc==927

* SOC 00
recode class16_mother_soc (0=9) if masoc00_cc==111
recode class16_mother_soc (0=9) if masoc00_cc==112
recode class16_mother_soc (0=9) if masoc00_cc==113
recode class16_mother_soc (0=11) if masoc00_cc==114
recode class16_mother_soc (0=9) if masoc00_cc==115
recode class16_mother_soc (0=10) if masoc00_cc==116
recode class16_mother_soc (0=9) if masoc00_cc==117
recode class16_mother_soc (0=10) if masoc00_cc==118
recode class16_mother_soc (0=10) if masoc00_cc==121
recode class16_mother_soc (0=10) if masoc00_cc==122
recode class16_mother_soc (0=10) if masoc00_cc==123
recode class16_mother_soc (0=5) if masoc00_cc==211
recode class16_mother_soc (0=5) if masoc00_cc==212
recode class16_mother_soc (0=5) if masoc00_cc==213
recode class16_mother_soc (0=13) if masoc00_cc==221
recode class16_mother_soc (0=13) if masoc00_cc==231
recode class16_mother_soc (0=5) if masoc00_cc==232
recode class16_mother_soc (0=9) if masoc00_cc==241
recode class16_mother_soc (0=9) if masoc00_cc==242
recode class16_mother_soc (0=5) if masoc00_cc==243
recode class16_mother_soc (0=14) if masoc00_cc==244
recode class16_mother_soc (0=14) if masoc00_cc==245
recode class16_mother_soc (0=6) if masoc00_cc==311
recode class16_mother_soc (0=6) if masoc00_cc==312
recode class16_mother_soc (0=6) if masoc00_cc==313
recode class16_mother_soc (0=14) if masoc00_cc==321
recode class16_mother_soc (0=14) if masoc00_cc==322
recode class16_mother_soc (0=14) if masoc00_cc==323
recode class16_mother_soc (0=15) if masoc00_cc==331
recode class16_mother_soc (0=14) if masoc00_cc==341
recode class16_mother_soc (0=14) if masoc00_cc==342
recode class16_mother_soc (0=9) if masoc00_cc==343
recode class16_mother_soc (0=15) if masoc00_cc==344
recode class16_mother_soc (0=6) if masoc00_cc==351
recode class16_mother_soc (0=10) if masoc00_cc==352
recode class16_mother_soc (0=10) if masoc00_cc==353
recode class16_mother_soc (0=10) if masoc00_cc==354
recode class16_mother_soc (0=6) if masoc00_cc==355
recode class16_mother_soc (0=9) if masoc00_cc==356
recode class16_mother_soc (0=11) if masoc00_cc==411
recode class16_mother_soc (0=11) if masoc00_cc==412
recode class16_mother_soc (0=11) if masoc00_cc==413
recode class16_mother_soc (0=12) if masoc00_cc==414
recode class16_mother_soc (0=11) if masoc00_cc==415
recode class16_mother_soc (0=11) if masoc00_cc==421
recode class16_mother_soc (0=7) if masoc00_cc==511
recode class16_mother_soc (0=7) if masoc00_cc==521
recode class16_mother_soc (0=7) if masoc00_cc==522
recode class16_mother_soc (0=7) if masoc00_cc==523
recode class16_mother_soc (0=7) if masoc00_cc==524
recode class16_mother_soc (0=7) if masoc00_cc==531
recode class16_mother_soc (0=7) if masoc00_cc==532
recode class16_mother_soc (0=7) if masoc00_cc==541
recode class16_mother_soc (0=7) if masoc00_cc==542
recode class16_mother_soc (0=15) if masoc00_cc==543
recode class16_mother_soc (0=7) if masoc00_cc==549
recode class16_mother_soc (0=15) if masoc00_cc==611
recode class16_mother_soc (0=15) if masoc00_cc==612
recode class16_mother_soc (0=15) if masoc00_cc==613
recode class16_mother_soc (0=15) if masoc00_cc==621
recode class16_mother_soc (0=15) if masoc00_cc==622
recode class16_mother_soc (0=16) if masoc00_cc==623
recode class16_mother_soc (0=15) if masoc00_cc==629
recode class16_mother_soc (0=15) if masoc00_cc==711
recode class16_mother_soc (0=16) if masoc00_cc==712
recode class16_mother_soc (0=12) if masoc00_cc==721
recode class16_mother_soc (0=8) if masoc00_cc==811
recode class16_mother_soc (0=8) if masoc00_cc==812
recode class16_mother_soc (0=8) if masoc00_cc==813
recode class16_mother_soc (0=8) if masoc00_cc==814
recode class16_mother_soc (0=16) if masoc00_cc==821
recode class16_mother_soc (0=7) if masoc00_cc==822
recode class16_mother_soc (0=8) if masoc00_cc==911
recode class16_mother_soc (0=8) if masoc00_cc==912
recode class16_mother_soc (0=8) if masoc00_cc==913
recode class16_mother_soc (0=8) if masoc00_cc==914
recode class16_mother_soc (0=11) if masoc00_cc==921
recode class16_mother_soc (0=12) if masoc00_cc==922
recode class16_mother_soc (0=16) if masoc00_cc==923
recode class16_mother_soc (0=8) if masoc00_cc==924
recode class16_mother_soc (0=8) if masoc00_cc==925

recode class16_mother_soc (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8_mother_soc)
label value class8_mother_soc class8_mother
recode class8_mother_soc (0=.)
tab class8_mother_soc

recode class8_mother_soc (3=1) if inlist(magold, 5, 6)
recode class8_mother_soc (5=1) if inlist(magold, 5, 6)
recode class8_mother_soc (7=1) if inlist(magold, 5, 6)
recode class8_mother_soc (4=1) if inlist(magold, 5, 6)
recode class8_mother_soc (6=1) if inlist(magold, 5, 6)
recode class8_mother_soc (8=1) if inlist(magold, 5, 6)

gen class8_parent_soc = class8_father_soc
replace class8_parent_soc = class8_mother_soc if class8_father_soc==.

gen class8_parent_tot = class8_parent_all
replace class8_parent_tot = class8_parent_soc if class8_parent_all==.

** Code respondents' class in UKHLS

**** Recode employment status for respondents

tab jbsemp

recode jbsemp (-9/-1=9), copyrest gen(emplrel_2)

label define emplrel_2 ///
1 "Employee" ///
2 "Self-employed" ///
9 "Missing"
label value emplrel_2 emplrel_2
tab emplrel_2

tab jssize
replace jssize=0 if jsboss==2
recode jssize (-8/-1=.) (0=0)(1/2=1)(3/11=2), gen(emplno_2)
label define emplno_2 ///
0 "0 employees" ///
1 "1-9 employees" ///
2 "10+ employees"
label value emplno_2 emplno_2
tab emplno_2


gen selfem_mainjob2=.
replace selfem_mainjob2=1 if emplrel_2==1 | emplrel_2==9
replace selfem_mainjob2=2 if emplrel_2==2 & emplno_2==0
replace selfem_mainjob2=2 if emplrel_2==3
replace selfem_mainjob2=3 if emplrel_2==2 & emplno_2==1
replace selfem_mainjob2=4 if emplrel_2==2 & emplno_2==2
label variable selfem_mainjob2 "Employment status for respondants"
label define selfem_mainjob2 ///
1 "Not self-employed" ///
2 "Self-empl without employees" ///
3 "Self-empl with 1-9 employees" ///
4 "Self-empl with 10 or more"
label value selfem_mainjob2 selfem_mainjob2
tab selfem_mainjob2


*************************************************
* Create Oesch class schema for respondents
*************************************************

gen class16_2 = -9

gen isco88_mainjob=jbisco88_cc
recode isco88_mainjob (-9=.) (-8=.) (10=.)


replace class16_2=. if isco88_mainjob==100
replace class16_2=9	if isco88_mainjob==111
replace class16_2=9	if isco88_mainjob==114
replace class16_2=9	if isco88_mainjob==121
replace class16_2=9	if isco88_mainjob==122
replace class16_2=9	if isco88_mainjob==123
replace class16_2=10 if isco88_mainjob==131
replace class16_2=5	if isco88_mainjob==211
replace class16_2=5	if isco88_mainjob==212
replace class16_2=5	if isco88_mainjob==213
replace class16_2=5	if isco88_mainjob==214
replace class16_2=5	if isco88_mainjob==221
replace class16_2=13 if isco88_mainjob==222
replace class16_2=13 if isco88_mainjob==223
replace class16_2=13 if isco88_mainjob==231
replace class16_2=13 if isco88_mainjob==232
replace class16_2=14 if isco88_mainjob==233
replace class16_2=13 if isco88_mainjob==234
replace class16_2=13 if isco88_mainjob==235
replace class16_2=9 if isco88_mainjob==241
replace class16_2=9 if isco88_mainjob==242
replace class16_2=13 if isco88_mainjob==243
replace class16_2=13 if isco88_mainjob==244
replace class16_2=14 if isco88_mainjob==245
replace class16_2=13 if isco88_mainjob==246
replace class16_2=9	if isco88_mainjob==247
replace class16_2=6	if isco88_mainjob==311
replace class16_2=6	if isco88_mainjob==312
replace class16_2=6	if isco88_mainjob==313
replace class16_2=6	if isco88_mainjob==314
replace class16_2=6	if isco88_mainjob==315
replace class16_2=6	if isco88_mainjob==321
replace class16_2=14 if isco88_mainjob==322
replace class16_2=14 if isco88_mainjob==323
replace class16_2=14 if isco88_mainjob==331
replace class16_2=14 if isco88_mainjob==332
replace class16_2=14 if isco88_mainjob==333
replace class16_2=14 if isco88_mainjob==334
replace class16_2=10 if isco88_mainjob==341
replace class16_2=10 if isco88_mainjob==342
replace class16_2=10 if isco88_mainjob==343
replace class16_2=10 if isco88_mainjob==344
replace class16_2=10 if isco88_mainjob==345
replace class16_2=14 if isco88_mainjob==346
replace class16_2=14 if isco88_mainjob==347
replace class16_2=14 if isco88_mainjob==348
replace class16_2=11 if isco88_mainjob==411
replace class16_2=11 if isco88_mainjob==412
replace class16_2=11 if isco88_mainjob==413
replace class16_2=11 if isco88_mainjob==414
replace class16_2=11 if isco88_mainjob==419
replace class16_2=11 if isco88_mainjob==421
replace class16_2=11 if isco88_mainjob==422
replace class16_2=15 if isco88_mainjob==511
replace class16_2=16 if isco88_mainjob==512
replace class16_2=16 if isco88_mainjob==513
replace class16_2=15 if isco88_mainjob==514
replace class16_2=15 if isco88_mainjob==516
replace class16_2=15 if isco88_mainjob==521
replace class16_2=15 if isco88_mainjob==522
replace class16_2=7 if isco88_mainjob==611
replace class16_2=7 if isco88_mainjob==612
replace class16_2=7 if isco88_mainjob==613
replace class16_2=7 if isco88_mainjob==614
replace class16_2=7	if isco88_mainjob==615
replace class16_2=7	if isco88_mainjob==711
replace class16_2=7	if isco88_mainjob==712
replace class16_2=7	if isco88_mainjob==713
replace class16_2=7	if isco88_mainjob==714
replace class16_2=7	if isco88_mainjob==721
replace class16_2=7	if isco88_mainjob==722
replace class16_2=7	if isco88_mainjob==723
replace class16_2=7	if isco88_mainjob==724
replace class16_2=7	if isco88_mainjob==731
replace class16_2=7	if isco88_mainjob==732
replace class16_2=7	if isco88_mainjob==733
replace class16_2=7	if isco88_mainjob==734
replace class16_2=7	if isco88_mainjob==741
replace class16_2=7	if isco88_mainjob==742
replace class16_2=7	if isco88_mainjob==743
replace class16_2=7	if isco88_mainjob==744
replace class16_2=8	if isco88_mainjob==811
replace class16_2=8	if isco88_mainjob==812
replace class16_2=8	if isco88_mainjob==813
replace class16_2=8	if isco88_mainjob==814
replace class16_2=8	if isco88_mainjob==815
replace class16_2=8	if isco88_mainjob==816
replace class16_2=8	if isco88_mainjob==817
replace class16_2=8	if isco88_mainjob==821
replace class16_2=8	if isco88_mainjob==822
replace class16_2=8	if isco88_mainjob==823
replace class16_2=8	if isco88_mainjob==824
replace class16_2=8	if isco88_mainjob==825
replace class16_2=8	if isco88_mainjob==826
replace class16_2=8	if isco88_mainjob==827
replace class16_2=8	if isco88_mainjob==828
replace class16_2=8	if isco88_mainjob==829
replace class16_2=7	if isco88_mainjob==831
replace class16_2=8	if isco88_mainjob==832
replace class16_2=7	if isco88_mainjob==833
replace class16_2=7	if isco88_mainjob==834
replace class16_2=16 if isco88_mainjob==911
replace class16_2=16 if isco88_mainjob==912
replace class16_2=16 if isco88_mainjob==913
replace class16_2=16 if isco88_mainjob==914
replace class16_2=16 if isco88_mainjob==915
replace class16_2=8	if isco88_mainjob==916
replace class16_2=8	if isco88_mainjob==921
replace class16_2=8	if isco88_mainjob==931
replace class16_2=8	if isco88_mainjob==932
replace class16_2=8	if isco88_mainjob==933

recode class16_2 (-9=.)

* Large employers (1)
replace class16_2=1 if selfem_mainjob2==4 & wave>18

* Self-employed professionals (2)

replace class16_2=2 if (selfem_mainjob2==2 | selfem_mainjob2==3) & inlist(class16_2, 5, 6, 9, 10, 13, 14)

* Small business owners with employees (3)

replace class16_2=3 if (selfem_mainjob2==3) & inlist(class16_2, 7, 8, 11, 12, 15, 16)


* Small business owners without employees (4)

replace class16_2=4 if (selfem_mainjob2==2) & inlist(class16_2, 7, 8, 11, 12, 15, 16)

label variable class16_2 "Respondent's Oesch class position - 16 classes"
label value class16_2 class16_r
tab class16_2

recode class16_2 (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8_2)
label variable class8_2 "Respondent's Oesch class position - 8 classes"
label value class8_2 class8_r
tab class8_2

recode class16_2 (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5), gen(class5_2)
label variable class5_2 "Respondent's Oesch class position - 5 classes"
label value class5_2 class5_r
tab class5_2

gen class8_tot=class8_r
replace class8_tot=class8_2 if class8_r==.


recode jbhas (-9/-1=.) (2=0), gen(working)
recode working (0=1) if jboff==1

gen part_time=jbft
recode part_time (-9/-7=0) (2=0)
replace part_time=jbft_dv if part_time==.
recode part_time (-9/-7=0) (2=0)

drop british_national
gen british_national=bornuk_dv
recode british_national (-9=.) (2=0)
tab british_national

gen birth_year = doby
replace birth_year = birthy if birth_year==.
recode birth_year (-9=.) (-1=.)
tab birth_year wave, nol

drop male
recode sex (-9/-7=.) (2=0), gen(male)

recode mastat_dv (-9/-1=.) (1=3) (2=1) (3=1) (4=2) (5=2) (6=3) (7=2) (8=.) (9=3) (10=1) , gen(civsta_us)

replace civsta_3=civsta_us if inrange(wave, 19, 27)
drop civsta_us

replace age=dvage if inrange(wave, 19, 27)
recode age(-9=.)
drop if age==.

recode fiyr (-9/-7=.), gen(income)

recode fimngrs_dv (-50000/0=.), gen(income2)
gen income2_yearly = income2*12

gen yearly_income= income
replace yearly_income=income2_yearly if wave>18
recode yearly_income (0=0.00000001)
gen lnincome= ln(yearly_income)


* EGP class location - 7 class version
recode jbgold (-10/0=.) (3/4=3) (5/7=4) (8=5) (9=6) (10/11=7), gen(egp_7)

label define egp_7 ///
1 "Upper service" ///
2 "Lower service" ///
3 "Routine non-manual" ///
4 "Petty bourgeoisie" ///
5 "Technicians & supervisors" ///
6 "Skilled manual" ///
7 "Non-skilled manual"

label values egp_7 egp_7

recode mrjgold (-10/0=.) (3/4=3) (5/7=4) (8=5) (9=6) (10/11=7), gen(lastegp_7)
label values lastegp_7 egp_7

replace egp_7=lastegp_7 if egp_7==.

recode magold (-10/0=.) (3/4=3) (5/7=4) (8=5) (9=6) (10/11=7), gen(ma_egp7)
label values ma_egp7 egp_7

recode pagold (-10/0=.) (3/4=3) (5/7=4) (8=5) (9=6) (10/11=7), gen(pa_egp7)
label values pa_egp7 egp_7

gen egp7_parent=pa_egp7
replace egp7_parent=ma_egp7 if egp7_parent==.

* Code vote in UKHLS
replace closest_party = vote4 if wave>18
recode closest_party (-9/-2=.) (96=.)

replace tomorrow_party = vote3 if wave>18
recode tomorrow_party (-9/-2=.) (96=.)

gen pref_party2=closest_party if wave>18
replace pref_party2=tomorrow_party if closest_party==. & wave>18
replace pref_party=pref_party2 if wave>18

recode pref_party2 (-1=0) (1=0) (2=1) (3/97=0), gen(pref_lab2)
replace pref_lab=pref_lab2 if wave>18

gen closest_left2 = vote4 if wave>18
recode closest_left2 (-9/-2=.) (-1=0) (1=0) (2=1) (3=0) (4=1) (5=0) (6=1) (7=0) (8=1) (9=0) (10=0) (11=1) (12=0) (13=0) (96=.) (97=0)

gen tomorrow_left2 = vote3 if wave>18
recode tomorrow_left2 (-9/-2=.) (-1=0) (1=0) (2=1) (3=0) (4=1) (5=0) (6=1) (7=0) (8=1) (9=0) (10=0) (11=1) (12=0) (13=0) (95=0) (96=.) (97=0)

gen pref_left2=closest_left2
tab closest_left2 tomorrow_left2, m
replace pref_left2=tomorrow_left2 if closest_left2==. & wave>18

replace pref_left=pref_left2 if wave>18

gen closest_left_ng2 = vote4 if wave>18
recode closest_left_ng2 (-9/-2=.) (-1=0) (1=0) (2=1) (3=0) (4=1) (5=0) (6=0) (7=0) (8=1) (9=0) (10=0) (11=1) (12=0) (13=0) (96=.) (97=0)

gen tomorrow_left_ng2 = vote3 if wave>18
recode tomorrow_left_ng2 (-9/-2=.) (-1=0) (1=0) (2=1) (3=0) (4=1) (5=0) (6=0) (7=0) (8=1) (9=0) (10=0) (11=1) (12=0) (13=0) (95=0) (96=.) (97=0)

gen pref_left_ng2=closest_left_ng2
tab closest_left_ng2 tomorrow_left_ng2, m // In principle this second item should only be asked to people who do not have a closest party
replace pref_left_ng2=tomorrow_left_ng2 if closest_left_ng2==. & wave>18

replace pref_left_ng=pref_left_ng2 if wave>18

drop closest_left
drop tomorrow_left
drop closest_left2
drop tomorrow_left2
drop pref_left2
drop pref_party2
drop pref_lab2
drop pref_left_ng2
drop closest_left_ng2
drop tomorrow_left_ng2

* Generations

recode birth_year (1893/1927=1) (1928/1945=2) (1946/1964=3) (1965/1980=4) (1981/1996=5) (1997/2012=6) ///
 , gen(generations)
 
label define generations ///
1 "1927 or earlier" ///
2 "Silent 1928-1945" ///
3 "Boomers 1946-1964" ///
4 "Gen X 1965-1980" ///
5 "Millennials 1981-1996" ///
6 "Gen Z 1997-2012"
label values generations generations

gen generations2=generations
recode generations2 (1/2=.) (6=.)

* Simplified measures of class and of mobility
recode class8_parent_tot (3=1) (5=1) (6=9) (2=9) , gen (simclass_parent)
recode simclass_parent (4=2) (7=3) (8=4) (9=5)
label define simclass 1"Old middle class" 2"Production wrkrs" 3"SCP" 4"Service wrkrs" 5"Others"
label values simclass_parent simclass

recode class8_tot (3=1) (5=1) (6=9) (2=9) , gen (simclass_r)
recode simclass_r (4=2) (7=3) (8=4) (9=5)
label values simclass_r simclass

recode simclass_r simclass_parent (1=4) (2=2) (3=3) (4=1), gen(simclass_r2 simclass_parent2)
label define simclass_r2 1"Service workers" 2"Production workers" 3 "SCP" 4"OMC" 5"Others"
label values simclass_r2 simclass_parent2 simclass_r2
tab simclass_r2 simclass_r 
tab simclass_parent2 simclass_parent2

* Transitions

gen trans=.
recode trans (.=1) if simclass_parent==2 & simclass_r==2 // * Immobile prod workers
recode trans (.=2) if simclass_parent==4 & simclass_r==4 //   Immobile service workers
recode trans (.=3) if simclass_parent==2 & simclass_r==4 // * Prod wkers - Serv wkers
recode trans (.=4) if simclass_parent==4 & simclass_r==2 //   Serv wkers - Prod wkers
recode trans (.=5) if simclass_parent==3 & simclass_r==3 // * Immobile SCP

recode trans (.=6) if simclass_parent==2 & simclass_r==3 // * Prod wkers - SCP
recode trans (.=7) if simclass_parent==4 & simclass_r==3 //   Serv wkers - SCP
recode trans (.=8) if simclass_parent==3 & simclass_r==2 //   SCP - worker
recode trans (.=8) if simclass_parent==3 & simclass_r==4 //   SCP - worker

recode trans (.=9) if simclass_parent==2 & simclass_r==1 // * Prod wkers - OMC
recode trans (.=10) if simclass_parent==4 & simclass_r==1 //  Serv wkers - OMC
recode trans (.=11) if simclass_parent==3 & simclass_r==1 // * SCP - OMC

recode trans (.=12) if simclass_parent==1 & simclass_r==2 //  OMC - workers
recode trans (.=12) if simclass_parent==1 & simclass_r==4 //  OMC - workers
recode trans (.=13) if simclass_parent==1 & simclass_r==3 // * OMC - SCP
recode trans (.=14) if simclass_parent==1 & simclass_r==1 // * Immobile OMC

recode trans (.=20) if simclass_parent==1 & simclass_r==5
recode trans (.=21) if simclass_parent==2 & simclass_r==5
recode trans (.=22) if simclass_parent==3 & simclass_r==5
recode trans (.=23) if simclass_parent==4 & simclass_r==5
recode trans (.=24) if simclass_parent==5 & simclass_r==1
recode trans (.=25) if simclass_parent==5 & simclass_r==2
recode trans (.=26) if simclass_parent==5 & simclass_r==3
recode trans (.=27) if simclass_parent==5 & simclass_r==4
recode trans (.=28) if simclass_parent==5 & simclass_r==5

label define trans ///
1 "Immobile prod workers" ///
2 "Immobile serv workers" ///
3 "Prod wkers - Serv wkers" ///
4 "Serv wkers - Prod wkers" ///
5 "Immobile SCP" ///
6 "Prod wkers - SCP" ///
7 "Serv wkers - SCP" ///
8 "SCP - Workers" ///
9 "Prod wkers - OMC" ///
10 "Serv wkers - OMC" ///
11 "SCP - OMC" ///
12 "OMC - Workers" ///
13 "OMC - SCP" ///
14 "Immobile OMC"
label values trans trans

rename part_time parttime
rename pref_left left

recode male (1=0) (0=1), gen(female)
rename class8_r class8_BHPS
rename class8_tot class8_r
rename class8_parent class8_parentBHPS
rename class8_parent_tot class8_parent

save BHPS_US_workfile.dta
